<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2021/7/2
  Time: 15:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title></title>
</head>
<body>
<h2>疫苗接种系统</h2>
<table border="1">
    <tr>
        <td><button onclick="location.href='add.jsp'">新增</button></td>
    </tr>
    <tr>
        <th>接种人姓名</th>
        <th>预约人身份证号</th>
        <th>接种状态</th>
        <th>预约接种日期日期</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${list}" var="rent">
        <tr>
            <td>${rent.userName}</td>
            <td>${rent.cardId}</td>
            <td>${rent.status==0 ? '预约' : '已接种'}</td>
            <td>${rent.bookingDate}</td>
            <td>
                <a href="javascript:void(0)" onclick="update(${rent.id},${rent.status})">${rent.status==0 ? '预约' : '已接种'}</a>
                <a href="javascript:void(0)" onclick="del(${rent.id})">删除</a>
            </td>
        </tr>
    </c:forEach>
</table>
<a href="ListServlet?currPage=1&pageSize=3">首页</a>
<c:if test="${ currPage>1 }">
    <a href="ListServlet?currPage=${ currPage-1 }&pageSize=3">上一页</a>
</c:if>
<c:if test="${ currPage<totalPage }">
    <a href="ListServlet?currPage=${ currPage+1 }&pageSize=3">下一页</a>
</c:if>
<a href="ListServlet?currPage=${ totalPage }&pageSize=3">尾页</a>

<script src="js/jquery-1.8.3.js"></script>
<script>
    function update(id,status) {
        if(status===1){
            status=0;
        }else{
            status=1;
        }

        if (confirm("确认吗？")){
            $.post("UpdateServlet","id="+id+"&status="+status,function (data) {
                if (data>0){
                    alert("成功");
                    location.href="ListServlet";
                }else{
                    alert("失败");
                }
            })
        }
    }

    function del(id) {
        if (confirm("确定删除吗？")) {
            $.post("DeleteServlet", "id=" + id, function (data) {
                if (data > 0) {
                    alert("删除成功");
                    location.href = "ListServlet"
                } else {
                    alert("删除失败");
                }
            })
        }
    }
</script>
</body>
</html>
